/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controler.formbeans;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author Maha
 */
public class RegisterationBean extends org.apache.struts.action.ActionForm {

    private String userName;
    private String email;
    private String password;
    private String confirmPassword;
    private String secretQuestion;
    private String answer;
    private String userType;
    private String msg;

    public RegisterationBean() {
        super();
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getConfirmPassword() {
        return confirmPassword;
    }

    public void setConfirmPassword(String confirmPassword) {
        this.confirmPassword = confirmPassword;
    }

    public String getSecretQuestion() {
        return secretQuestion;
    }

    public void setSecretQuestion(String secretQuestion) {
        this.secretQuestion = secretQuestion;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    public String getUserType() {
        return userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if (getUserName() == null || getUserName().length() < 3) {
            errors.add("name", new ActionMessage("errors.username"));
        }
        if (getEmail() == null) {
            errors.add("emptymail", new ActionMessage("errors.emptymail"));
        }
        if (!getEmail().matches("^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$")) {
            errors.add("unmatch", new ActionMessage("errors.unmatchedmail"));
        }
        if (getPassword() == null || getPassword().length() < 8) {
            errors.add("password", new ActionMessage("errors.password"));
        }
        if (!getConfirmPassword().equals(getPassword())) {
            errors.add("confirmpassword", new ActionMessage("errors.confirmpassword"));
        }
        if (getSecretQuestion().equals("Please Select One")) {
            errors.add("question", new ActionMessage("errors.secretquestion"));
        }
        if (getAnswer() == null || getAnswer().length() < 3) {
            errors.add("answer", new ActionMessage("errors.secretanswer"));
        }
        if (getUserType().equals("Please Select One")) {
            errors.add("type", new ActionMessage("errors.usertype"));
        }

        return errors;
    }
}
